package net.starelement.digwartnt.game;

import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.item.Item;
import cn.nukkit.level.Location;
import net.starelement.gamelib.game.GameBase;

import java.util.Map;
import java.util.UUID;

/**  StarElement MainGame 游戏类
 *
 * @author Ruok233
 * @since NukkitX API 1.0.9 | StarElement Project v1-alpaca
 *
 * create: 2019/12/09
 */

public class Game extends GameBase {

    private Server server = Server.getInstance();

    private Map<UUID, Player> map;
    private Location redTeam = new Location();
    private Location blueTeam = new Location();

    public Game() {
        this.map = server.getOnlinePlayers();
        redTeam.x = 35;
        redTeam.y = 9;
        redTeam.z = 14;
        blueTeam.x = 35;
        blueTeam.y = 9;
        blueTeam.z = -5;
    }

    @Override
    public void start() {

        //格式化地图
        Ground.getInstance().format();

        //玩家分队传送到游戏位置
        boolean team = true;
        for (Player value : map.values()) {
            if (team) {
                value.teleport(redTeam);
                team = false;
            } else {
                value.teleport(blueTeam);
                team = true;
            }
            value.getInventory().addItem(Item.get(261));
            value.getInventory().addItem(Item.get(262));
            value.sendTitle("§b§a游戏开始！");
        }

        server.broadcastMessage("§bDigwarTNT §f游戏开始！");

    }

    @Override
    public void stop() {

    }
}
